const util = require("../../../utils/util.js");
const config = require("../../../utils/config.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    questionList: [],
    index: 0,
    // text:"这是一个页面"
    postList: [{
        "name": "收取关山五十州上句是什么？",
        "daan": "A",
        "content": ["男儿何不带吴钩", "天若有情天亦老", "大漠沙如雪", "主父西游何时归"]
      },
      {
        "name": "危乎高哉上句是什么？",
        "daan": "B",
        "content": ["明朝散发弄扁舟", "蜀道难，难于上青天", "床前明月光", "吾爱孟夫子"]
      },
      {
        "name": "感时花溅泪下句是什么？",
        "daan": "C",
        "content": ["也无风雨也无晴", "明月几时有", "恨别鸟惊心", "老夫聊发少年狂"]

      }
    ],
    index: 0,
    bc_default: '#FBFBFB',
    bc_right: '#98FB98',
    bc_wrong: '#FF99B4',
    bcA: '',
    bcB: '',
    bcC: '',
    bcD: '',
    ny: '显示答案',
    defen: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  getData: function() {
    var that = this;
    let url = config.BaseUrl + "t/question/list";
    util.request(url, "GET").then(function(res) {
      if (res.code == 200) {
        that.setData({
          questionList: res.data
        })
      }
    })
  },


  nextQuestion: function() {
    var that = this;
    if (that.data.index < postData.postList.length - 1) {
      this.setData({
        index: that.data.index + 1,
        bcA: that.data.bc_default,
        bcB: that.data.bc_default,
        bcC: that.data.bc_default,
        bcD: that.data.bc_default,
        ny: '显示答案'

      });
    }
  },
  lastQuestion: function() {
    var that = this;
    if (that.data.index > 0) {
      this.setData({
        index: that.data.index - 1,
        ny: '显示答案'
      });
    }
  },
  btnOpClick: function(e) {
    var that = this;
    var select = e.currentTarget.id;
    var jieg = postData.postList[that.data.index].daan;
    if (select == jieg) {
      if (that.data.index < postData.postList.length - 1) {
        if (select == 'A') {
          this.setData({
            bcA: that.data.bc_right
          });
        } else if (select == 'B') {
          this.setData({
            bcB: that.data.bc_right
          });
        } else if (select == 'C') {
          this.setData({
            bcC: that.data.bc_right
          });
        } else if (select == 'D') {
          this.setData({
            bcD: that.data.bc_right
          });
        }
        that.nextQuestion();
        this.setData({
          defen: that.data.defen + 2
        })
      } else {
        if (select == 'A') {
          this.setData({
            bcA: that.data.bc_right
          });
        } else if (select == 'B') {
          this.setData({
            bcB: that.data.bc_right
          });
        } else if (select == 'C') {
          this.setData({
            bcC: that.data.bc_right
          });
        } else if (select == 'D') {
          this.setData({
            bcD: that.data.bc_right
          });
        }
        that.gotonext();
      }
    } else {
      if (select == 'A') {
        this.setData({
          bcA: that.data.bc_wrong
        });
      } else if (select == 'B') {
        this.setData({
          bcB: that.data.bc_wrong
        });
      } else if (select == 'C') {
        this.setData({
          bcC: that.data.bc_wrong
        });
      } else if (select == 'D') {
        this.setData({
          bcD: that.data.bc_wrong
        });
      } else if (select == 'E') {
        this.setData({
          bcE: that.data.bc_wrong
        });
      }
    }
  },
  gotonext: function() {
    wx.navigateTo({
      url: './../tiaozhuan/tiaozhuan',
    })
  },
  xianshi: function() {
    var that = this;
    this.setData({
      ny: '答案是：' + that.data.postList[that.data.index].daan
    })
  }

})